package com.wsc.wisdomchinaqinghe.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.wsc.wisdomchinaqinghe.R;
import com.wsc.wisdomchinaqinghe.Tools.Tools;
import com.wsc.wisdomchinaqinghe.javaBean.YuYueListBean;

import java.util.List;

/**
 * Created by Administrator on 2017/2/27 0027.
 */

public class WodeYuyueAdapter extends BaseAdapter{
    private Context context;
    private List<YuYueListBean> list;

    public WodeYuyueAdapter(Context context, List<YuYueListBean> list) {
        this.context = context;
        this.list = list;
    }

    @Override
    public int getCount() {
        return list.size();
    }

    @Override
    public Object getItem(int position) {
        return list.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(final int position, View convertView, ViewGroup parent) {
        Louyu_holder holder=null;
        View view=convertView;
        if (view==null){
            view= LayoutInflater.from(context).inflate(R.layout.wodeyuyue_item,null);
            holder= new Louyu_holder(view);
            view.setTag(holder);
        }else {
            holder= (Louyu_holder) view.getTag();
        }
        holder.time.setText(Tools.formatDateTimeMMDD(Tools.formatData(list.get(position).getCreateDate())));
        holder.title.setText(list.get(position).getTitle());
        holder.type.setText(list.get(position).getStreetName());
        Glide.with(context).load(list.get(position).getImg()).into(holder.item_icon);

        switch (list.get(position).getType()) {
            case 0:
                holder.tv_shenhe.setText("待处理");
                holder.tv_shenhe.setTextColor(context.getResources().getColor(R.color.D7F2));
                break;
            case 1:
                holder.tv_shenhe.setText("已接单");
                holder.tv_shenhe.setTextColor(context.getResources().getColor(R.color.D7F2));
                break;
            case 2:
                holder.tv_shenhe.setText("待评价");
                holder.tv_shenhe.setTextColor(context.getResources().getColor(R.color.CD1F));
                break;
            case 3:
                holder.tv_shenhe.setText("失败");
                holder.tv_shenhe.setTextColor(context.getResources().getColor(R.color.FC5812));
                break;
            case 4:
                holder.tv_shenhe.setText("完成");
                holder.tv_shenhe.setTextColor(context.getResources().getColor(R.color.CD1F));
                break;

        }
        return view;
    }

    public class Louyu_holder  {
        ImageView item_icon;
        TextView title, type, time, tv_shenhe;

        public Louyu_holder(View itemView) {
            item_icon = (ImageView) itemView.findViewById(R.id.icon);
            title = (TextView) itemView.findViewById(R.id.title);
            type = (TextView) itemView.findViewById(R.id.type);
            time = (TextView) itemView.findViewById(R.id.time);
            tv_shenhe = (TextView) itemView.findViewById(R.id.tv_shenhe);

        }
    }
}
